obj-m := vserial_stj.o

KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)

all:
	$(MAKE) -C $(KDIR) M=$(PWD) modules

clean:
	$(MAKE) -C $(KDIR) M=$(PWD) clean

install:
	$(MAKE) -C $(KDIR) M=$(PWD) modules_install

uninstall:
	rm -f /lib/modules/$(shell uname -r)/extra/vserial_simple.ko
	depmod -a

load:
	sudo insmod vserial_stj.ko tcp_ip=127.0.0.1 tcp_server_port=5000 num_devices=1 reconnect_interval=10

load_multi:
	sudo insmod vserial_stj.ko tcp_ip=127.0.0.1 tcp_server_port=5000 num_devices=4 reconnect_interval=10

load_fast:
	sudo insmod vserial_stj.ko tcp_ip=127.0.0.1 tcp_server_port=5000 num_devices=1 reconnect_interval=1

load_slow:
	sudo insmod vserial_stj.ko tcp_ip=127.0.0.1 tcp_server_port=5000 num_devices=1 reconnect_interval=30

unload:
	sudo rmmod vserial_stj

# 状态查看工具
status:
	@echo "=== 虚拟串口状态 ==="
	@if [ -f "/proc/vserial_stj/status" ]; then \
		cat /proc/vserial_stj/status; \
	else \
		echo "模块未加载或状态文件不存在"; \
	fi

quick:
	@./quick_status.sh

monitor:
	@echo "启动实时监控..."
	@./vserial_monitor.sh

# 设置脚本权限
setup:
	chmod +x vserial_config.sh
	chmod +x load_from_config.sh
	chmod +x generate_test.sh
	chmod +x vserial_unload.sh
	chmod +x vserial_status.sh
	chmod +x vserial_monitor.sh
	chmod +x quick_status.sh 